package com.lei2j.client;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


@SpringBootApplication
//当使用Eureka作为注册中心时,使用此注解较好
@EnableEurekaClient
//通用的发现服务注解，可用于其它注册中心（如：Zookeeper）时使用
//@EnableDiscoveryClient
@RestController
public class ClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(ClientApplication.class, args);
    }

    @Autowired
    private HttpServletRequest request;

    @RequestMapping("/test")
    public ResponseEntity test(@RequestParam("name")String name){
        System.out.println(request.getHeader("Cache-Control"));
        return ResponseEntity.ok(name);
    }

    @RequestMapping("/fallback")
    public ResponseEntity fallback(){
        String header = request.getHeader("Test-Header");
        return ResponseEntity.ok("client error,header:"+header);
    }
}

